package com.elink.enginerring.blog;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.blog.co.BlogCo;
import com.elink.enginerring.blog.service.IBlogService;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;

@Controller
@RequestMapping("view/blog")
@Api(value="博文的接口")
public class BlogController {
	@Autowired
	private IBlogService blogService;
	
	/**
	 * 分页获取博文列表
	 * @param co
	 * @return
	 */
	@RequestMapping(value="/getList",method=RequestMethod.GET)
	@ApiOperation(value="分页获取博文列表",httpMethod="GET")
	@ResponseBody
	public Map<String, Object>getList(@ModelAttribute @Valid BlogCo co){
		
		DataSourceContextHolder.setDbType(DataSourceType.DBUSER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 

		return blogService.getList(co);
	}

	/**
	 * 博文详情
	 * @param blodId
	 * @return
	 */
	@RequestMapping(value="/getInfo",method=RequestMethod.GET)
	@ApiOperation(value="获取博文详情",httpMethod="GET")
	@ResponseBody
	public Map<String, Object> getInfo(@ApiParam(value="博文主键",required=true)@RequestParam(value="blogId",required=true)String blogId,
			@ApiParam(value="类别0--个人博文1--企业博文 2--个人简历的站内作品,默认为0",required=true,defaultValue="0")
	@RequestParam(value="type",required=true,defaultValue="0")int type){
		DataSourceContextHolder.setDbType(DataSourceType.DBUSER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		return blogService.getInfo(blogId,type);
	}
}
